package com.hzgj.bcl.soa.cicada.lb;

import com.hzgj.bcl.soa.cicada.Lifecycle;
import com.hzgj.bcl.soa.cicada.router.Router;
import com.hzgj.bcl.soa.cicada.sender.Sender;

/**
 * Interface that defines the operations for a software loadbalancer. A typical
 * loadbalancer minimally need a set of servers to loadbalance for, a method to
 * mark a particular server to be out of rotation and a call that will choose a
 * server from the existing list of server.
 *
 * @author stonse
 */
public interface LoadBalancer extends Lifecycle {

    /**
     * Choose a server from load balancer.
     *
     * @param key An object that the load balancer may use to determine which server to return. null if
     *            the load balancer does not use this parameter.
     * @return server chosen
     */
    Sender chooseSender(Object key);

    /**
     * To be called by the clients of the load balancer to notify that a Server is down
     * else, the LB will think its still Alive until the next Ping cycle - potentially
     * (assuming that the LB Impl does a ping)
     *
     * @param sender Server to mark as down
     */
    void markSenderDown(Sender sender, String service);

    Router getRouter();

}
